package com.ljx.shiro.controller;

import com.ljx.shiro.common.RespBean;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
*权限异常处理，控制器都应该继承
*/
/**
 * @Author: Ljx
 * @Date: 2022/4/25 22:19
 * @role:
 */
@Controller
@RequestMapping(value = "/Error")
public class ExceptionController {
    //拒绝请求
    @RequestMapping(value = "/notoken",method = RequestMethod.GET)
    @ResponseBody
    public RespBean notoken(){
        return RespBean.error("Token无效");
    }

    //无权时的异常处理
    @ExceptionHandler({UnauthorizedException.class})
    @RequestMapping(value = "/unauthorized",method = RequestMethod.GET)
    @ResponseBody
    public RespBean unauthorized(){
        return RespBean.error("无权访问");
    }

}

